import React from 'react';
import InputItem from '../../../components/InputItem';
import {Input,InputNumber, message} from 'antd';
import DepartmentController from '@/services/System/DepartmentController';
const {TextArea}= Input
class NewProjectOne extends React.Component {
    constructor(props) {
        super(props);
        let storageData = JSON.parse(sessionStorage.getItem('newLeanProject_one'))
        this.state = { 
            datas:storageData||{},
            userInfo:JSON.parse(sessionStorage.getItem('userInfo')),
            departmentList:[]
     };
    }
    componentDidMount(){
        this.props.onRef(this)
        this.getDepartmentList()
    }
    handleChange=(datas)=>{
        this.setState({datas})
    }
    getDepartmentList=()=>{
        let {userInfo} = this.state
        let provinceDepartmentList = []
        let cityDepartmentList = []
        let departmentList = []
        DepartmentController.getList({to_stop:'1'}).then(r=>{
            if(r&&r.status===200){
                r.data.rows.map(item=>{
                    if(item.type==='省级'){
                        provinceDepartmentList.push({code:item.id+"/"+item.name,name:item.name})}
                    if(item.type==='市级'){
                        cityDepartmentList.push({code:item.id+"/"+item.name,name:item.name})}
                })
                if(userInfo.roleName.includes('市级')){
                    departmentList = cityDepartmentList
                }
                if(userInfo.roleName.includes('省级')){
                    departmentList = provinceDepartmentList
                }
                this.setState({departmentList})
                
            }
        })
    }
    saveDatas=()=>{
        let {datas}=this.state
        if(!datas.projectName){
            message.error('请输入课题名称')
            return;
        }
        if(!datas.proposalName){
            message.error('请输入建议名称')
            return;
        }
        if(!datas.problemDescription){
            message.error('请输入存在问题描述')
            return;
        }
        if(!datas.proposal){
            message.error('请输入具体措施')
            return;
        }
        if(!datas.proposalDepartment){
            message.error('请选择被建议部门')
            return;
        }
        
        sessionStorage.setItem('newLeanProject_one',JSON.stringify(datas))
        return true

    }
    render() {
        const {datas,departmentList} = this.state
        const columns=[
            {name:'课题名称',keyName:'projectName',valueType:'text',style:{width:600},value:datas.projectName},
            {name:'建议名称',keyName:'proposalName',valueType:'text',style:{width:600},value:datas.proposalName},
            {name:'存在问题描述',keyName:'problemDescription',valueType:'textArea',style:{width:600},value:datas.problemDescription},
            {name:'具体措施',keyName:'proposal',valueType:'textArea',style:{width:600},value:datas.proposal},
            {name:'被建议部门',keyName:'proposalDepartment',valueType:'select',style:{width:600},value:datas.proposalDepartment,selectDatas:departmentList},

        ]
        return (
            <div>
                <InputItem columns={columns} onChange={this.handleChange}/>
            </div>
        );
    }
}

export default NewProjectOne;